package cn.sicnu.cs.employment.service.impl;

import cn.sicnu.cs.employment.domain.entity.BackgroundInfo;
import cn.sicnu.cs.employment.mapper.BackgroundInfoMapper;
import cn.sicnu.cs.employment.service.IBackgroundInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
@Deprecated
public class BackgroundInfoServiceImpl implements IBackgroundInfoService {

    private final BackgroundInfoMapper infoMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class, propagation = Propagation.REQUIRED)
    public void insertInfo(BackgroundInfo info) {
        infoMapper.insert(info);
    }

    @Override
    public List<BackgroundInfo> getBackInfoById(Long empId) {
        QueryWrapper<BackgroundInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("emp_id", empId).orderByDesc("time");
        return infoMapper.selectList(wrapper);
    }

    @Override
    public boolean isAvailable(Long id) {
        long create = infoMapper.getCreateTime(id).getTime();
        long now = System.currentTimeMillis();
        return now - create < 7 * 24 * 60 * 60 * 1000 ;
    }

    @Override
    public void deleteInfoById(Long id) {
        infoMapper.deleteById(id);
    }

}